/*
* Created by: yyf
* Description: 基金管理--拟设立基金列表页
*/
<template>
    <div>
        <!--右开始-->
        <div class="right">
            <el-row>
                <el-col :span="6">
                    <el-button icon="el-icon-plus" class="ca-color-download" @click="fundAdd" :disabled="!isAuthListAdd">新建拟设立基金</el-button>
                </el-col>
                <el-col :span="18">
                    <div class="ca-pull-right">
                        <el-input v-model="param.name" placeholder="基金名称，支持模糊查询" class="ca-w-280 ca-m-r-15" @keyup.native.enter="fundList()">
                            <el-button slot="append" @click="fundList()" icon="el-icon-search"></el-button>
                        </el-input>
                        <el-button type="primary" :disabled="!isAuthListDownload" @click="downloadFile">下载</el-button>
                    </div>
                </el-col>
            </el-row>
            <div class="ca-m-t-15">
                <el-table
                    :data="fundData"
                    @sort-change="sortChange"
                    class="ca-table">
                    <el-table-column label="序号" type="index" width="70px" align="center">
                        <template slot-scope="scope">
                            <csRedDot :label="scope.$index+1+''" :showDot="scope.row.red==1?true:false" :type="1"></csRedDot>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="基金名称"
                        sortable="custom"
                        prop="fundName">
                        <template slot-scope="scope">
                            <el-tooltip :content="scope.row.fundName" placement="top" class="item">
                                <el-button type="text" :disabled="!isAuthDetailSee" @click="toDetail(scope.row)" class="ca-underline ca-text-over-flow-ellipsis">{{scope.row.fundName}}</el-button>
                            </el-tooltip>
                            <!--<span :disabled="!isAuthDetailSee" @click="toDetail(scope.row)" class="ca-underline">{{scope.row.fundName}}</span>-->
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="managerName"
                        sortable="custom"
                        label="基金经理"
                        show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column
                        prop="establishTime"
                        sortable="custom"
                        width="120px"
                        label="拟设立日期">
                    </el-table-column>
                    <el-table-column
                        prop="lastContact"
                        sortable="custom"
                        width="130px"
                        label="最后更新时间">
                    </el-table-column>
                    <el-table-column
                        prop="region"
                        sortable="custom"
                        show-overflow-tooltip
                        label="基金地区"
                        show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column
                        prop="scale"
                        sortable="custom"
                        show-overflow-tooltip
                        :render-header="renderTitle"
                        label="拟设立规模</br>(万元)">
                        <template slot-scope="scope">
                            {{scope.row.scale | format1}}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="progress"
                        sortable="custom"
                        width="90px"
                        label="节点">
                    </el-table-column>
                    <el-table-column
                        width="80px"
                        label="操作">
                        <template slot-scope="scope">
                            <el-button @click="deleteData(scope.row)" :disabled="!isAuthListDel" type="text" size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="ca-m-t-20 ca-align-center">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="param.pageIndex"
                    :page-sizes="vuePageSizes"
                    :page-size="vuePageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalCount">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from './api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                scale: '拟设立规模' + '(万元)',
                fundData: [],
                totalCount: 0,   // 查询到数据个数
                totalPage: 0,     // 查询到数据页数
                param: {
                    orderBy: '', // 排序字段
                    sort: '', // desc降序，asc正序
                    name: '',
                    pageIndex: 1,
                    pageSize: 30,
                },
                fundNameKey: '',
                isAuthListSee: isNoAuth('拟设立基金-列表页-查看'),
                isAuthListAdd: isNoAuth('拟设立基金-列表页-新建'),
                isAuthListDel: isNoAuth('拟设立基金-列表页-删除'),
                isAuthListDownload: isNoAuth('拟设立基金-列表页-下载'),
                isAuthDetailSee: isNoAuth('拟设立基金-基金详情-查看'),
            }
        },
        watch: {

        },
        props: {},
        mounted() {
            this.fundList();
        },
        methods: {
            // 排序
            sortChange(val) {
                if (val.prop) {
                    this.param.orderBy = val.prop;
                    this.param.sort = val.order === 'ascending' ? 'asc' : 'desc';
                } else {
                    this.param.orderBy = '';
                    this.param.sort = '';
                }
                this.fundList();
            },
            // 获取基金列表页
            async fundList() {
                this.fundNameKey = this.param.name;
                let {data, resCode} = await apiHttp(api.ESTABLISHING_FUNDS_LIST,this.param)
                if (resCode === STATUS_HTTP_SUCCESS) {
                    this.fundData = data.resultData;
                    this.totalCount = data.totalCount;
                    this.totalPage = data.totalPage;
                }
            },
            // 下载文件
            downloadFile() {
                if (this.fundData.length === 0) {
                    this.$message({
                        type: 'warning',
                        message: '暂无数据'
                    })
                } else {
                    window.open(this.baseURL + api.DOWNLOAD_FILE.url + '?X-Token=' + this.$store.state.user.token + '&type=5&name=' + this.fundNameKey + '&itemNode=&prostatus=&fundType=' );
                }
            },
            // 添加拟设立基金
            fundAdd() {
                this.$router.push({name: 'establishing-funds-add', params: {openWindow: true}})
            },
            // 删除单条基金
            deleteData(row) {
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    showClose: false
                }).then(() => {
                    apiHttp(api.ESTABLISHING_FUNDS_DEL, {id: row.id}).then(res=>{
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        if (res.resCode === STATUS_HTTP_SUCCESS) {
                            this.fundList();
                        }
                    })
                })
            },
            // 查看详情
            toDetail(row) {
                this.$router.push({name: 'establishing-funds', params: {itemId: row.id, tabIndex: '0', openWindow: true}})
            },
            handleSizeChange(val) {
                this.param.pageSize = val;
                this.fundList();
            },
            handleCurrentChange(val) {
                this.param.pageIndex = val;
                this.fundList();
            }
        },
        components: {
            'csRedDot': require('__components/red-dot'), // 选项卡小红点
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
